{% extends "base.html" %}

{% block title %}Leaderboard - BunnySpell{% endblock %}

{% block styles %}
<link rel="stylesheet" href="{{ url_for('static', filename='leaderboard.css') }}">
{% endblock %}

{% block content %}
<div class="lb_container">
    <h1 class="lb_title">
        Leaderboard
    </h1>
    
    <div class="lb_wrapper">
        <!-- Players Table -->
        <div class="lb_table">
            <div class="lb_header">
                <div>Rank</div>
                <div>Player</div>
                <div >Score</div>
                <div>Games</div>
                <div>Avg</div>
                <div>Last</div>
            </div>
            
            <div class="lb_body">
                {% for user in top_users %}
                    <div class="lb_row {% if loop.index == 1 %}lb_first{% endif %} {% if current_user.is_authenticated and user.username == current_user.username %}lb_current-user{% endif %}">
                        <div>
                            #{{ loop.index }}
                            {% if loop.index == 1 %}👑{% endif %}
                        </div>
                        <div>{{ user.username }}</div>
                        <div>{{ user.total_score }} pts</div>
                        <div>{{ user.total_games }}</div>
                        <div>{{ "%.1f"|format(user.avg_score) }}</div>
                        <div>{{ user.last_played.strftime('%Y-%m-%d') }}</div>
                    </div>
                {% endfor %}
            </div>
        </div>

        <!-- Pagination -->
        {% if pagination.pages > 1 %}
        <div class="lb_pagination">
            {% if pagination.has_prev %}
                <a href="{{ url_for('leaderboard', page=pagination.prev_num) }}" class="lb_page-link">&laquo; Previous</a>
            {% endif %}

            {% for page in pagination.iter_pages(left_edge=2, left_current=2, right_current=3, right_edge=2) %}
                {% if page %}
                    {% if page == pagination.page %}
                        <span class="lb_page-link lb_active">{{ page }}</span>
                    {% else %}
                        <a href="{{ url_for('leaderboard', page=page) }}" class="lb_page-link">{{ page }}</a>
                    {% endif %}
                {% else %}
                    <span class="lb_page-link lb_dots">...</span>
                {% endif %}
            {% endfor %}

            {% if pagination.has_next %}
                <a href="{{ url_for('leaderboard', page=pagination.next_num) }}" class="lb_page-link">Next &raquo;</a>
            {% endif %}
        </div>
        {% endif %}
    </div>
</div>
{% endblock %}
